#! user/bin/python
# -*- coding: utf-8 -*-

"""
Created on 2021/7/20 9:12

@File: query_api_for_siteid.py
@Author: LT
@Description: 不再需要去数据库从库中查询必要的数据了，直接访问接口，输入相应的关键字，就可以获得必要的参数；
"""
from requests import post
import json


class QueryApiForSiteId:
    def __init__(self, station_name, **kwargs):
        self.link = 'https://comp.wzies.com/backend/company/site/userSiteInfos'
        self.headers = {'Content-Type': 'application/json'}  # payload形式必须有请求头表示它是什么类型的，这里用json类型！
        self.data = {
            "key": station_name,
            "companyId": "comp_00000001",
            "userId": "user_00000001"
        }
        self.res = self.__request()

    def __request(self):
        res = post(url=self.link, data=json.dumps(self.data), headers=self.headers)
        res.close()
        return res


if __name__ == '__main__':
    exp = QueryApiForSiteId("方大控股有限公司")
    print(exp.res.json())

    # -------------->此站点的返回体是<-----------------：
    # {
    #     "code": "1",
    #     "msg": "SUCCESS",
    #     "data": {
    #         "site": [
    #             {
    #                 "site_name": "方大控股有限公司",
    #                 "site_id": "site_00002621",
    #                 "level1": "1",
    #                 "objectId": "2186c27a1d800000"
    #             },
    #             {
    #                 "site_name": "方大控股有限公司（乐清）",
    #                 "site_id": "site_00011177",
    #                 "level1": "1",
    #                 "objectId": "274cfb95e8800000"
    #             }
    #         ]
    #     },
    #     "timestamp": 0
    # }
